package com.aaa.dao;


import com.aaa.entity.State;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Repository
public class StateDaoImpl  {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private RowMapper<State> rowMapper=new RowMapper<State>() {
        public State mapRow(ResultSet resultSet, int i) throws SQLException {
            State state=new State();
            state.setSid(resultSet.getLong("sid"));
            state.setSname(resultSet.getString("sname"));
            return state;
        }
    };
    public List<State> listAll() {
        String sql="select sid,sname from state";
        List<State> result = this.jdbcTemplate.query(sql, rowMapper);
        return result;
    }
}
